<template>
    <div class="content_panel project_modules deal-list">
        <div class="content_panel_top">
            <h3 class="panel_title">
                <span>{{$t('pageTitle.automaticAouponIssuance')}}</span>
            </h3>
            <el-form ref="form" :model="form" :rules="rules" :inline="false" class="module_form">
                <el-row :gutter="10">
                    <el-col :span="4">
                        <el-form-item prop="discountCouponType"><!--券名称-->
                            <el-select v-model="form.discountCouponType" clearable :placeholder="$t('operation.couponName')" style="width: 100%">
                                <el-option v-for="(type, $index) in keyMap.couponType()" :key="$index" :label="type.label" :value="type.value"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col><!--券名称-->
                    <el-col :span="4">
                        <el-form-item prop="appName"><!--app名称-->
                            <el-select v-model="form.appName" :placeholder="$t('system.appName')" clearable style="width:100%;">
                                <el-option v-for="item in appList" :key="item.id" :value="item.name" :label="item.name"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col><!--节点名称-->
                    <el-col :span="4">
                        <el-form-item prop="triggerNode"><!--节点名称-->
                            <el-select v-model="form.triggerNode" :placeholder="$t('common.triggerNode')" clearable style="width:100%;">
                                <el-option   el-option v-for="item in triggerNode" :key="item.value" :value="item.value" :label="item.label"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col><!--状态-->
                    <el-col :span="4">
                        <el-form-item prop="nodeStatus"><!--状态-->
                            <el-select v-model="form.nodeStatus" :placeholder="$t('common.status')" clearable style="width:100%;">
                                <el-option   el-option v-for="item in aouponStatus" :key="item.value" :value="item.value" :label="item.label"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-button @click="search" icon="el-icon-search" type="primary">{{ $t('common.search') }}</el-button>
                        <el-button @click="issueCoupon" icon="el-icon-plus" type="primary">{{ $t('common.addCoupon') }}</el-button>
                    </el-col>

                </el-row>
            </el-form>
        </div>

        <div class="module_content">
            <div class="content_panel project_modules">
                <div class="table_list">
                    <el-table ref="table" :data="tableData" style="width: 100%;" :max-height="tableMaxHeight" :highlight-current-row="true">
                        <el-table-column prop="discountCouponType" :label="$t('operation.couponName')" :min-width="$i18n.locale==='zhCN'?120:200">
                            <template slot-scope="{row}">{{ keyMap.couponType(row.discountCouponType) }}</template>
                        </el-table-column><!--券名称-->
                        <el-table-column prop="appName" :label="$t('system.appName')" min-width="120"></el-table-column><!--APP名称-->
                        <el-table-column prop="triggerNode" :label="$t('common.triggerNode')" min-width="120">
                            <template slot-scope="{ row }">{{ row.triggerNode | switchTriggerNode }}</template>
                        </el-table-column><!--触发节点-->
                        <el-table-column prop="discountAmount" :label="$t('operation.discountAmount')" min-width="120"></el-table-column><!--面额-->
                        <el-table-column prop="validityPeriod" :label="$t('operation.validityPeriod')" min-width="120"></el-table-column><!--有效期-->
                        <el-table-column prop="createTime" :label="$t('common.createTime')" min-width="180">
                            <template slot-scope="{ row }">{{ row.createTime | formatDate('yyyy-MM-dd hh:mm:ss') }}</template>
                            <!--创建时间-->
                        </el-table-column>
                        <el-table-column prop="updateTime" :label="$t('common.updateTime')" min-width="180">
                            <template slot-scope="{ row }">{{ row.updateTime | formatDate('yyyy-MM-dd hh:mm:ss') }}</template>

                            <!--更新时间-->
                        </el-table-column>
                        <!--状态-->
                        <el-table-column :label="$t('finance.status')" prop="nodeStatus" width="150">
                            <template slot-scope="{row}">
                                <el-switch
                                    @change='switchChange(row)'
                                    v-model.number="row.nodeStatysBolean"
                                    active-color="#47c5b2"
                                    inactive-color="#DCDFE6">
                                </el-switch>
                            </template>
                        </el-table-column>

                        <el-table-column :label="$t('common.operation')" min-width="120"><!-- 操作 -->
                            <template slot-scope="{ row }">
                                <el-button @click="edit(row)" type="primary" size="mini">{{ $t('common.edit') }}</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                </div>
                <!--分页组件-->
                <pagination @pageChange="pageChange" :page="page"></pagination>
            </div>
        </div>

        <!--发放优惠券弹框-->
        <el-dialog
            :title="dialogTitle"
            :visible.sync="issueDialog.isVisible"
            width="700px"
            :close-on-click-modal="false"
            class="issueDialogForm"><!--优惠券发放-->
            <div>
                <el-form ref="issueDialog.form" :model="issueDialog.form" :rules="issueDialog.rules" >
                    <div class="box">
                        <div class="box-sort">
                            <!--券名称-->
                            <el-form-item prop="discountCouponType" :label="$t('operation.couponName')">
                                <!-- <el-input v-model="issueDialog.form.type" :placeholder="$t('operation.couponName')" style="width: 100%"></el-input> -->
                                <el-select v-model="issueDialog.form.discountCouponType" clearable :placeholder="$t('operation.couponName')" style="width: 100%">
                                    <el-option v-for="(type, $index) in keyMap.couponType()" :key="$index" :label="type.label" :value="type.value"></el-option>
                                </el-select>
                            </el-form-item>
                            <!--触发节点-->
                            <el-form-item prop="triggerNode" :label="$t('common.triggerNode')">
                                <el-select v-model="issueDialog.form.triggerNode" :placeholder="$t('common.triggerNode')" clearable style="width:100%;">
                                    <el-option   el-option v-for="item in triggerNode" :key="item.value" :value="item.value" :label="item.label"></el-option>
                                </el-select>
                            </el-form-item>
                            <!--优惠券有效期-->
                            <el-form-item prop="validityPeriod" :label="$t('common.couponValidity')">
                                <el-input v-model="issueDialog.form.validityPeriod" :placeholder="$t('common.plsInptCouponDay')" style="width: 100%"></el-input>
                            </el-form-item>
                        </div>
                        <div class="box-sort">
                            <!--App名称-->
                            <el-form-item prop="appName" :label="$t('system.appName')">
                                <el-select v-model="issueDialog.form.appName" :placeholder="$t('system.appName')" clearable style="width:100%;">
                                    <el-option v-for="item in appList" :key="item.id" :value="item.name" :label="item.name"></el-option>
                                </el-select>
                            </el-form-item>
                            <!--优惠券面额-->
                            <el-form-item prop="discountAmount" :label="$t('operation.couponDiscountAmount')">
                                <el-input v-model="issueDialog.form.discountAmount" :placeholder="$t('operation.plsInputDiscountAmount')" style="width: 100%"></el-input>
                            </el-form-item>

                        </div>
                    </div>
                </el-form>
            </div>
            <span slot="footer" class="dialog-footer">
                    <el-button :disabled="issueDialog.isDisabledBtn" type="primary" @click="submint">{{ $t('common.confirmOk') }}</el-button><!--确认发放-->
                    <el-button @click="issueCouponClose">{{ $t('common.cancel') }}</el-button><!--取 消-->
                </span>
        </el-dialog>

    </div>
</template>

<script src="./main.js"></script>

<style lang="scss" scoped>
.issueDialogForm {
    .el-dialog__body {
        padding:10px 15px;
    }
    .el-dialog__header {
        text-align: center;
    }
    .el-dialog__footer {
        text-align: center;
        .el-button {
            margin:0 20px;
        }
    }
    .el-form-item {
        margin: 0 0 16px 0;
        padding:0 15px;
    }
    .el-form-item__label {
        line-height:30px;
    }
    .box {
        display: flex;
        .box-sort {
            flex: 1;
            overflow: hidden;
        }
    }
    .confirmInfo {
        border-top:1px solid #ddd;
        padding:15px 0 0 0;
        margin:10px 0 0 0;
        line-height:30px;
        .title {
            font-weight:bold;
            font-size: 16px;
        }
    }
}
</style>
